package ko;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuff.Mode;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class StageView extends SurfaceView implements SurfaceHolder.Callback {
	private Canvas tc;
	private SurfaceHolder sh;
	private Bitmap bmp;
	private Canvas can;
	private Matrix m;

	public StageView(Context c) {
		super(c);
		K.context = c;
		sh = this.getHolder();
		sh.addCallback(this);
		//this.setFocusable(true);
		bmp = Bitmap.createBitmap(K.W, K.H, Config.ARGB_8888);
		can = new Canvas(bmp);
		m = new Matrix();

		m.setScale(K.SysRW, K.SysRH);
		
		K.view = can;
	}
	
	public boolean onTouchEvent(MotionEvent e) {
		return true;
	}

	public void lockCanvas() {
		K.view = sh.lockCanvas();
		K.render.drawRect(K.rect, K.paint);
	}
	public void unlockCanvas() {
		sh.unlockCanvasAndPost(K.view);
	}
//	public void lockCanvas() {
//		tc = sh.lockCanvas();
//		K.render.drawRect(K.rect, K.paint);
//	}
//	public void unlockCanvas() {
//		tc.drawBitmap(bmp, m, K.paint);
//		sh.unlockCanvasAndPost(tc);
//	}

	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
	}

	public void surfaceCreated(SurfaceHolder arg0) {
		Log.i("StageView", "surfaceCreated");
		K.engine.StartRun();
	}

	public void surfaceDestroyed(SurfaceHolder arg0) {
		K.engine.setRun(false);
	}
}
